package 算法.手动输入数据练习;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author coderFu
 * @create 2022/3/19
 */
public class CoderTest3 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()){
            String  p = sc.nextLine();
            String s = sc.nextLine();
            System.out.println(find(s.toString()));

        }
    }
    public static int find(String s){
        char[] chars = s.toCharArray();
        int max = 0;
        for(int i=0; i<chars.length;i++){
            Stack<Character> stack = new Stack<>();
            int count = 0;
            if (chars[i] == ')'){
                continue;
            }else {
                stack.push(chars[i]);
            }
            for(int j=i+1; j<chars.length; j++){
                if(chars[j] == '('){
                    stack.push(chars[j]);
                }else{
                    if(stack.size() >0) {
                        Character pop = stack.pop();
                        if (pop == '(') {
                            count++;
                        } else {
                            break;
                        }
                    }
                }
            }
            max =  Math.max(max,count);
        }
        return max*2;
    }
}
